import { defineStore } from 'pinia'

export const useChatIdStore = defineStore('chatId', () => {
  function getChatId() {
    return sessionStorage.getItem('chatId')
  }

  function setChatId(id: number) {
    if (id <= 0) return
    sessionStorage.setItem('chatId', id.toString())
  }

  function getRandomChatId() {
    const min = Math.ceil(1)
    const max = Math.floor(1000000000)
    return Math.floor(Math.random() * (max - min + 1)) + min
  }

  return { getChatId, setChatId, getRandomChatId }
})
